package cn.edu.tju.se.auth.domain;

import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import com.fasterxml.jackson.annotation.JsonIgnore;

//@Entity(name="Auth_Role")
@Entity(name="auth_role")
public class Role {
	@Id
	@GeneratedValue
	private Long id;

	private String name;
	
//	@JsonIgnore
//	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
//	@JoinTable(name = "Auth_r_User_Role", 
//	joinColumns = { @JoinColumn(name = "Role_ID", referencedColumnName = "id") }, 
//	inverseJoinColumns = { @JoinColumn(name = "User_ID", referencedColumnName = "id") })
//	@JoinTable(name = "auth_r_user_group_role", 
//	joinColumns = { @JoinColumn(name = "Role_ID", referencedColumnName = "id") }, 
//	inverseJoinColumns = { @JoinColumn(name = "User_ID", referencedColumnName = "id") })
//	private Set<User> users;
	
//	@JsonIgnore
//	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
//	@JoinTable(name = "Auth_r_Group_Role", 
//	joinColumns = { @JoinColumn(name = "Role_ID", referencedColumnName = "id") }, 
//	inverseJoinColumns = { @JoinColumn(name = "Group_ID", referencedColumnName = "id") })
//	@JoinTable(name = "auth_r_user_group_role", 
//	joinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") }, 
//	inverseJoinColumns = { @JoinColumn(name = "group_id", referencedColumnName = "id") })
//	private Set<Group> groups;

	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
//	@JoinTable(name = "Auth_r_Role_Privilege", 
//	joinColumns = { @JoinColumn(name = "Role_ID", referencedColumnName = "id") }, 
//	inverseJoinColumns = { @JoinColumn(name = "Privilege_ID", referencedColumnName = "id") })
	@JoinTable(name = "auth_r_role_permission",
	joinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")},
	inverseJoinColumns = {@JoinColumn(name = "permission_id", referencedColumnName ="id")})
	private Set<Privilege> privileges;
	
	@JsonIgnore
	@OneToMany
	@JoinColumn(name = "role_id")
	private Set<Udr> myUdr;

	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Set<Udr> getMyUdr() {
		return myUdr;
	}


	public void setMyUdr(Set<Udr> myUdr) {
		this.myUdr = myUdr;
	}


	public Set<Privilege> getPrivileges() {
		return privileges;
	}


	public void setPrivileges(Set<Privilege> privileges) {
		this.privileges = privileges;
	}


	
	
}
